package AnalysisApi;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class JsonUtils {
	
	
    public static String parseObjToJson(Object object) {
        String string = null;
        try {
            //string = JSON.toJSONString(object);
            string = JSONObject.toJSONString(object);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return string;
    }

    /**
     * 灏咼son瀛楃涓蹭俊鎭浆鎹㈡垚瀵瑰簲鐨凧ava瀵硅薄
     *
     * @param json json瀛楃涓插璞�
     * @param c    瀵瑰簲鐨勭被鍨�
     */
    public static <T> T parseJsonToObj(String json, Class<T> c) {
        try {
            //涓や釜閮芥槸鍙鐨勶紝璧风爜鎴戞祴璇曠殑鏃跺�欐槸娌￠棶棰樼殑銆�
            //JSONObject jsonObject = JSONObject.parseObject(json);
            JSONObject jsonObject = JSON.parseObject(json);
            return JSON.toJavaObject(jsonObject, c);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return null;
    }
}
